import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default {
  state: {
    //权限列表
    menuList: [],
    //导航列表
    permList: [],
    hasRoute: false,
    editableTabsValue: "Index",
    editableTabs: [
      {
        title: "首页",
        name: "Index"
      }
    ]
  },
  mutations: {
    setMenuList(state, obj) {
      state.menuList = obj;
    },
    setPermList(state, obj) {
      state.permList = obj;
    },
    queryHasRoute(state, obj) {
      state.hasRoute = obj;

      //存到session中
      sessionStorage.setItem("hasRoute", obj);
    },
    addTab(state, tab) {
      let index = -1;
      let item;
      for (item in state.editableTabs) {
        if (state.editableTabs[item].name === tab.name) {
          index = 1;
        }
      }

      //判断是否包含tabs 不包含在添加 否则直接跳到当前存在的标签页
      if (index <= -1) {
        state.editableTabs.push({
          title: tab.title,
          name: tab.name
        });
      }

      state.editableTabsValue = tab.name;
    },
    resetState: state => {
      state.token = "";
      state.menuList = [];
      state.permList = [];
      state.hasRoute = false;
      state.editableTabsValue = "Index";
      state.editableTabs = [
        {
          title: "首页",
          name: "Index"
        }
      ];
    }
  },
  actions: {}
};
